namespace Core.Features
{
    using System;
    using System.Linq;
    using Base;
    using Contracts.Enums;
    using Contracts.Interfaces;
    using Resources;


    public sealed class InjectedAccumulatorAmount<T> : FeatureBase<object>
    {
        public InjectedAccumulatorAmount() { }

        public InjectedAccumulatorAmount(T value)
            : base(value) { }
        /// <summary>
        /// Obtains the feature name
        /// </summary>
        public override string Name
        {
            get { return "Accumulator amount"; }
        }
        /// <summary>
        /// Obtains the feature group
        /// </summary>
        public override FeatureGroupsEnum FeatureGroup { get { return FeatureGroupsEnum.Specific; } }
        /// <summary>
        /// Obtains the feature type
        /// </summary>
        public override FeaturesEnum FeatureType { get { return FeaturesEnum.InjectedAccumulatorAmount; } }
        /// <summary>
        /// Obtains or defines the feature unit
        /// </summary>
        public override string Unit { get { return Traduction.label_unit_AP; } }

        /// Calculate the modified feature value
        /// </summary>
        public override void SetModifiedValue(IAgent agent, IRobot robot)
        {
            if (agent == null || robot == null) return;

            // extensions
            double extensionBonus = agent.Extensions.SumModifiersValues(FeatureTypesEnum.Robot, this.FeatureType);
            // SensorAmplifiers modules
            double moduleBonus = robot.Modules.SumModifiersValues(FeatureTypesEnum.Robot, this.FeatureType, ModuleGroupsEnum.SensorAmplifiers);

            double temp = (double)Value * (1 + extensionBonus) * (1 + moduleBonus);

            ModifiedValue = IsRounded
                ? Math.Round(temp, 0, MidpointRounding.AwayFromZero)
                : Math.Round(temp, 2);
        }
    }
}